package com.selune.online.ordering.system.project.customer.controller;

import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.api.pojo.order.dto.OrderDTO;
import com.selune.online.ordering.system.project.api.pojo.order.vo.OrderOverviewVO;
import com.selune.online.ordering.system.project.api.pojo.order.vo.OrderVO;
import com.selune.online.ordering.system.project.api.service.customer.ICustomerOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author  xiaoyp
 * @date 2020/02/20
 */

@Slf4j
@RestController
@RequestMapping("/api/v1/ordering/customer/order")
@Api("消费者订单管理控制器")
public class CustomerOrderController {

	@Autowired
	private ICustomerOrderService iCustomerOrderService;
	
	@ApiOperation(value = "创建订单", notes = "创建订单")
	@ApiImplicitParam(value = "orderDTO", name = "订单DTO", required = true, dataType = "OrderDTO", paramType = "body")
	@PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<OrderVO> saveOrder(@RequestBody OrderDTO orderDTO) {
		return iCustomerOrderService.saveOrder(orderDTO);
	}
	
	@ApiOperation(value = "订单支付", notes = "订单支付", httpMethod = "POST")
	@ApiImplicitParam(value = "orderId", name = "订单id", required = true, dataType = "Long", paramType = "query")
	@PostMapping(value = "/pay/{orderId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> payOrder(@PathVariable("orderId") Long orderId) {
		return iCustomerOrderService.payOrder(orderId);
	}
	
	@ApiOperation(value = "订单取消", notes = "订单取消", httpMethod = "POST")
	@ApiImplicitParam(value = "orderId", name = "订单id", required = true, dataType = "Long", paramType = "query")
	@PostMapping(value = "/cancel/{orderId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<Boolean> cancelOrder(@PathVariable("orderId") Long orderId) {
		return iCustomerOrderService.cancelOrder(orderId);
	}
	
	@ApiOperation(value = "订单列表", notes = "订单列表", httpMethod = "GET")
	@ApiImplicitParam(value = "orderVO", name = "订单详情", required = true, dataType = "orderVO", paramType = "query")
	@GetMapping(value = "/list/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<List<OrderOverviewVO>> listOrder(@PathVariable("userId") Long userId) {
		return iCustomerOrderService.listOrder(userId);
	}
	
	@ApiOperation(value = "根据orderId查找订单", notes = "根据orderId查找订单")
	@ApiImplicitParam(value = "orderId", name = "订单id", required = true, dataType = "Long", paramType = "query")
	@GetMapping(value = "/get/{orderId}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Response<OrderVO> getOrderById(@PathVariable("orderId") Long orderId) {
		return iCustomerOrderService.getOrderById(orderId);
	}

}
